package org.dtrd.modules.record.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.SneakyThrows;
import org.dtrd.common.util.DateUtils;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.device.entity.bean.xty.XtySugarRecord;
import org.dtrd.modules.record.entity.bean.SugarValueBean;

import javax.persistence.*;
import java.text.ParseException;
import java.util.Date;

@Data
@Table(name = "dtrd_ent_rd_signin_sugar_value")
public class DtrdEntRdSigninSugarValue {

    @Id
    @Column(name = "data_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO)
    private Integer dataId;

    @Column(name = "patient_id")
    private Integer patientId;

    /**
     * 记录日期
     */
    @Column(name = "record_date")
    private Date recordDate;

    /**
     * 记录时间
     */
    @Column(name = "record_time")
    private Date recordTime;

    /**
     * 1-早餐前,2-早餐后,3-午餐前,4-午餐后,5-晚餐前,6-晚餐后,7-睡前,8-凌晨
     */
    @Column(name = "sugar_value_time_type_id")
    private Integer sugarValueTimeTypeId;

    /**
     * 血糖值
     */
    @Column(name = "sugar_value_sugar_value")
    private Float sugarValueSugarValue;

    /**
     * 备注
     */
    @Column(name = "sugar_value_remark")
    private String sugarValueRemark;

    /**
     * 0-客户端,9-微信,10-瞬感蓝牙版,11-瞬感移动版,12-小糖医,13-爱奥乐,14-小程序
     */
    @Column(name = "sugar_value_source_type")
    private Integer sugarValueSourceType;

    /**
     * 血糖值测量 0-未知,1-偏高,2-正常,3-偏低
     */
    @Column(name = "sugar_value_type")
    private Integer sugarValueType;

    /**
     * 瞬感设备IMEI
     */
    @Column(name = "sugar_values_shungan_imei")
    private String sugarValuesShunganImei;

    /**
     * 小糖医IMEI
     */
    @Column(name = "sugar_values_xty_imei")
    private String sugarValuesXtyImei;

    @Column(name = "create_time")
    private Date createTime;

    @Column(name = "is_del")
    private Integer isDel;

    /**
     * 照片以 竖线 | 拼接
     */
    @Column(name = "record_photo")
    private String recordPhoto;

    /**
     * 记录类型, 0-打卡, 1-建档
     */
    private Integer sugarValueRecordArchiveTag;

    public DtrdEntRdSigninSugarValue(){}

    public DtrdEntRdSigninSugarValue(Integer patientId, Integer sugarValueTimeTypeId,
                                     Float sugarValueSugarValue, Integer sugarValueRecordArchiveTag) {
        this.patientId = patientId;
        // yyyy-MM-dd HH:mm:ss
        this.recordDate = DateUtils.getDateYMD();
        // yyyy-MM-dd
        this.recordTime = DateUtils.getDate();
        this.sugarValueTimeTypeId = sugarValueTimeTypeId;
        this.sugarValueSugarValue = sugarValueSugarValue;
        this.sugarValueRecordArchiveTag = sugarValueRecordArchiveTag;
    }

    public Integer getSugarValueRecordArchiveTag() {
        return sugarValueRecordArchiveTag;
    }

    public void setSugarValueRecordArchiveTag(Integer sugarValueRecordArchiveTag) {
        this.sugarValueRecordArchiveTag = sugarValueRecordArchiveTag;
    }

    /**
     * @return data_id
     */
    public Integer getDataId() {
        return dataId;
    }

    /**
     * @param dataId
     */
    public void setDataId(Integer dataId) {
        this.dataId = dataId;
    }

    /**
     * @return patient_id
     */
    public Integer getPatientId() {
        return patientId;
    }

    /**
     * @param patientId
     */
    public void setPatientId(Integer patientId) {
        this.patientId = patientId;
    }

    /**
     * 获取记录日期
     *
     * @return record_date - 记录日期
     */
    public Date getRecordDate() {
        return recordDate;
    }

    /**
     * 设置记录日期
     *
     * @param recordDate 记录日期
     */
    public void setRecordDate(Date recordDate) {
        this.recordDate = recordDate;
    }

    /**
     * 获取记录时间
     *
     * @return record_time - 记录时间
     */
    public Date getRecordTime() {
        return recordTime;
    }

    /**
     * 设置记录时间
     *
     * @param recordTime 记录时间
     */
    public void setRecordTime(Date recordTime) {
        this.recordTime = recordTime;
    }

    /**
     * 获取1-早餐前,2-早餐后,3-午餐前,4-午餐后,5-晚餐前,6-晚餐后,7-睡前,8-凌晨
     *
     * @return sugar_value_time_type_id - 1-早餐前,2-早餐后,3-午餐前,4-午餐后,5-晚餐前,6-晚餐后,7-睡前,8-凌晨
     */
    public Integer getSugarValueTimeTypeId() {
        return sugarValueTimeTypeId;
    }

    /**
     * 设置1-早餐前,2-早餐后,3-午餐前,4-午餐后,5-晚餐前,6-晚餐后,7-睡前,8-凌晨
     *
     * @param sugarValueTimeTypeId 1-早餐前,2-早餐后,3-午餐前,4-午餐后,5-晚餐前,6-晚餐后,7-睡前,8-凌晨
     */
    public void setSugarValueTimeTypeId(Integer sugarValueTimeTypeId) {
        this.sugarValueTimeTypeId = sugarValueTimeTypeId;
    }

    /**
     * 获取血糖值
     *
     * @return sugar_value_sugar_value - 血糖值
     */
    public Float getSugarValueSugarValue() {
        return sugarValueSugarValue;
    }

    /**
     * 设置血糖值
     *
     * @param sugarValueSugarValue 血糖值
     */
    public void setSugarValueSugarValue(Float sugarValueSugarValue) {
        this.sugarValueSugarValue = sugarValueSugarValue;
    }

    /**
     * 获取备注
     *
     * @return sugar_value_remark - 备注
     */
    public String getSugarValueRemark() {
        return sugarValueRemark;
    }

    /**
     * 设置备注
     *
     * @param sugarValueRemark 备注
     */
    public void setSugarValueRemark(String sugarValueRemark) {
        this.sugarValueRemark = sugarValueRemark;
    }

    /**
     * 获取0-客户端,9-微信,10-瞬感蓝牙版,11-瞬感移动版,12-小糖医,13-爱奥乐,14-小程序
     *
     * @return sugar_value_source_type - 0-客户端,9-微信,10-瞬感蓝牙版,11-瞬感移动版,12-小糖医,13-爱奥乐,14-小程序
     */
    public Integer getSugarValueSourceType() {
        return sugarValueSourceType;
    }

    /**
     * 设置0-客户端,9-微信,10-瞬感蓝牙版,11-瞬感移动版,12-小糖医,13-爱奥乐,14-小程序
     *
     * @param sugarValueSourceType 0-客户端,9-微信,10-瞬感蓝牙版,11-瞬感移动版,12-小糖医,13-爱奥乐,14-小程序
     */
    public void setSugarValueSourceType(Integer sugarValueSourceType) {
        this.sugarValueSourceType = sugarValueSourceType;
    }

    /**
     * 获取血糖值测量 0-未知,1-偏高,2-正常,3-偏低
     *
     * @return sugar_value_type - 血糖值测量 0-未知,1-偏高,2-正常,3-偏低
     */
    public Integer getSugarValueType() {
        return sugarValueType;
    }

    /**
     * 设置血糖值测量 0-未知,1-偏高,2-正常,3-偏低
     *
     * @param sugarValueType 血糖值测量 0-未知,1-偏高,2-正常,3-偏低
     */
    public void setSugarValueType(Integer sugarValueType) {
        this.sugarValueType = sugarValueType;
    }

    /**
     * 获取瞬感设备IMEI
     *
     * @return sugar_values_shungan_imei - 瞬感设备IMEI
     */
    public String getSugarValuesShunganImei() {
        return sugarValuesShunganImei;
    }

    /**
     * 设置瞬感设备IMEI
     *
     * @param sugarValuesShunganImei 瞬感设备IMEI
     */
    public void setSugarValuesShunganImei(String sugarValuesShunganImei) {
        this.sugarValuesShunganImei = sugarValuesShunganImei;
    }

    /**
     * 获取小糖医IMEI
     *
     * @return sugar_values_xty_imei - 小糖医IMEI
     */
    public String getSugarValuesXtyImei() {
        return sugarValuesXtyImei;
    }

    /**
     * 设置小糖医IMEI
     *
     * @param sugarValuesXtyImei 小糖医IMEI
     */
    public void setSugarValuesXtyImei(String sugarValuesXtyImei) {
        this.sugarValuesXtyImei = sugarValuesXtyImei;
    }

    /**
     * @return create_time
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @return is_del
     */
    public Integer getIsDel() {
        return isDel;
    }

    /**
     * @param isDel
     */
    public void setIsDel(Integer isDel) {
        this.isDel = isDel;
    }

    /**
     * 获取照片以 竖线 | 拼接
     *
     * @return record_photo - 照片以 竖线 | 拼接
     */
    public String getRecordPhoto() {
        return recordPhoto;
    }

    /**
     * 设置照片以 竖线 | 拼接
     *
     * @param recordPhoto 照片以 竖线 | 拼接
     */
    public void setRecordPhoto(String recordPhoto) {
        this.recordPhoto = recordPhoto;
    }

    public DtrdEntRdSigninSugarValue init() {
        isDel = 0;
        createTime = new Date();
        return this;
    }

    @SneakyThrows
    public DtrdEntRdSigninSugarValue parseFromDTO(SugarValueBean dto) {
        this.dataId = dto.getId();
        this.patientId = dto.getPatientId();
        this.sugarValueTimeTypeId = dto.getType();
        this.recordPhoto = dto.getRecordPhoto();
        this.sugarValueRemark = dto.getRemark();
        this.sugarValueSugarValue = dto.getValue();
        this.recordDate = DateUtils.parseDate(dto.getTime(), DateUtils.date_sdf.get().toPattern());
        this.recordTime = DateUtils.parseDate(dto.getTime(), DateUtils.datetimeFormat.get().toPattern());
        this.sugarValueTimeTypeId = dto.getType();
        this.sugarValueRecordArchiveTag = 0;
        this.sugarValueSourceType = Constant.SugarSourceType.SOURCE_SGBL_BLE.getType();
        return this;
    }

    public DtrdEntRdSigninSugarValue parseFromXtyRecord(XtySugarRecord xtyRecord) {
        sugarValueTimeTypeId = xtyRecord.getTimeType();
        sugarValuesXtyImei = xtyRecord.getDeviceImei();
        sugarValueSugarValue = xtyRecord.getSugar().floatValue();
        sugarValueSourceType = Constant.SugarSourceType.SOURCE_XTY.getType();
        try {
            recordTime = DateUtils.parseDate(xtyRecord.getCreateTime(), DateUtils.datetimeFormat.get().toPattern());
            recordDate = DateUtils.parseDate(xtyRecord.getCreateTime(), DateUtils.date_sdf.get().toPattern());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return this;
    }
}